package com.cooksys.film_rental.bo.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cooksys.film_rental.bo.ActorBo;
import com.cooksys.film_rental.dao.ActorDao;
import com.cooksys.film_rental.model.Actor;
import com.cooksys.film_rental.model.Film;
import com.cooksys.film_rental.model.FilmActor;

@Service("ActorBo")
public class ActorBoImpl implements ActorBo {

	@Autowired(required = true)
	private ActorDao actorDao;

	@Override
	public Actor getActorByActorId(Short actorId) {
		return this.actorDao.getActorByActorId(actorId);
	}

	@Override
	public List<Actor> searchActorsByPartialName(String partialName) {
		return this.actorDao.searchActorsByPartialName(partialName);
	}

	@Override
	public Actor getActorbyActorId(String actorId) {

		try {

			Short actorIdAsShort = Short.valueOf(actorId);
			return this.getActorByActorId(actorIdAsShort);

		} catch (NumberFormatException e) {

			System.err
					.println("Could not parse Short value for actorId from string: "
							+ actorId);
			e.printStackTrace();
			System.err.println("Returning null value...");
			return null;

		}

	}

	@Override
	public List<Actor> searchActorsByFilm(Film film) {
		return this.actorDao.searchActorsByFilm(film);
	}

	@Override
	public Actor getActorByFilmActor(FilmActor filmActor) {
		return this.actorDao.getActorByFilmActor(filmActor);
	}

	@Override
	public List<Actor> getAllActors() {
		return this.actorDao.getAllActors();
	}

}
